﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace assignment7
{
    public partial class addOrderForm : Form
    {
        public OrderService myOrderService;

        public addOrderForm()
        {
            InitializeComponent();
            DataGridViewColumn col1 = new DataGridViewColumn();
            DataGridViewCell cell = new DataGridViewTextBoxCell();
            col1.CellTemplate = cell;
            col1.HeaderText = "序号";
            addOrderForm_orderitemview.Columns.Add(col1);
            DataGridViewColumn col2 = new DataGridViewColumn();
            DataGridViewCell cel2 = new DataGridViewTextBoxCell();
            col2.CellTemplate = cell;
            col2.HeaderText = "货物";
            addOrderForm_orderitemview.Columns.Add(col2);
            DataGridViewColumn col3 = new DataGridViewColumn();
            DataGridViewCell cel3 = new DataGridViewTextBoxCell();
            col3.CellTemplate = cel3;
            col3.HeaderText = "数量";
            addOrderForm_orderitemview.Columns.Add(col3);
            DataGridViewColumn col4 = new DataGridViewColumn();
            DataGridViewCell cel4 = new DataGridViewTextBoxCell();
            col4.CellTemplate = cel4;
            col4.HeaderText = "单价";
            addOrderForm_orderitemview.Columns.Add(col4);
        }

        private void addOrderForm_Load(object sender, EventArgs e)
        {

        }

        private void addOrder_action_click(object sender, EventArgs e)
        {
            int rows_num = addOrderForm_orderitemview.Rows.Count;
            int columns_num = addOrderForm_orderitemview.Columns.Count;
            List<orderitem> temoOrderitem = new List<orderitem>();
            for (int i = 0; i < rows_num; i++)
            {
                orderitem neworderitem = new orderitem();
                if (addOrderForm_orderitemview.Rows[i].Cells[1].Value == null) break;
                neworderitem.Name = addOrderForm_orderitemview.Rows[i].Cells[1].Value.ToString();
                neworderitem.Number = int.Parse(addOrderForm_orderitemview.Rows[i].Cells[2].Value.ToString());
                neworderitem.Price = double.Parse(addOrderForm_orderitemview.Rows[i].Cells[3].Value.ToString());
                temoOrderitem.Add(neworderitem);
            }
            Order temporder = new Order(int.Parse(this.addOrder_orderid.Text),this.addOrder_ordercustomer.Text,this.addOrder_date.Text,temoOrderitem);
            temporder.Money = temporder.getPriceInAll();
            this.myOrderService.order.Add(temporder);
        }
    }
}
